package com.zxy.zxyrpc.protocol;

import lombok.Getter;

/**
 * 协议消息的类型枚举
 *
 * @author zxy
 * @since 2025/5/22
 **/
@Getter
public enum ProtocolMessageTypeEnum {
    REQ(0),
    RES(1),
    HEART_BEAT(2),
    OTHERS(3);
    private final int key;

    ProtocolMessageTypeEnum(int key) {
        this.key = key;
    }

    /**
     * 根据 key 获取枚举
     *
     * @param key 消息类型key
     * @return 消息对象枚举
     */
    public static ProtocolMessageTypeEnum getEnumByKey(int key) {
        for (ProtocolMessageTypeEnum anKey : ProtocolMessageTypeEnum.values()) {
            if (anKey.key == key) {
                return anKey;
            }
        }
        return null;
    }
}
